#include "stdafx.h"
#include "LuaZAManager.h"

#include "map"
#include "string"
#include "comutil.h"
#pragma comment(lib, "comsupp.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

class LuaPlusTableMap
{
public:
	LuaPlusTableMap(LuaPlus::LuaObject& obj)
	{
		_Load(obj);
	}

	_variant_t operator[] (LPCSTR szKey)
	{
		MAP_KEY_VALUE::iterator it = m_map.find(szKey);
		if (it!=m_map.end())
		{
			return it->second;
		}
		return _variant_t();
	}

private:
	void _Load(LuaPlus::LuaObject& obj)
	{
		LuaTableIterator luaTable(obj);
		
		do 
		{
			if (luaTable.IsValid())
			{
				LuaObject& key = luaTable.GetKey();
				LuaObject& value = luaTable.GetValue();

				_variant_t vValue;
				int nType = value.Type();
				switch (nType)
				{
				case LUA_TNUMBER:
					vValue = value.GetNumber();
					break;
				case LUA_TSTRING:
					vValue = value.GetString();
					break;
				case LUA_TWSTRING:
					vValue = value.GetWString();
					break;
				case LUA_TBOOLEAN:
					vValue = value.GetBoolean();
					break;
				default:
					ASSERT(FALSE);
					break;
				}
			
				const char* szKey = key.GetString();
				m_map.insert(MAP_KEY_VALUE::value_type(szKey, vValue));
			}
		} while (luaTable.Next());
	}

private:
	typedef std::map<std::string, _variant_t> MAP_KEY_VALUE;
	MAP_KEY_VALUE m_map;
};

void LuaUIShowConfig( LuaPlus::LuaObject obj )
{
	LuaPlusTableMap infoMap(obj);

	_bstr_t szName = infoMap["zaName"];
	
	
	

}
